package controllers

import (
	_"platform_stato/dao/mysql"
	"github.com/astaxie/beego/orm"
	"fmt"
)

type IndexController struct {
	Coding
}

//func init(){
//	orm.RegisterModel(new(Sys_pro))
//}

func (this *IndexController) Add_user(){
	req := this.Ctx.Request
	
	game_name := this.GetString("game_name")
	server_type := this.GetString("server_type")
	database := this.GetString("database")
	ip := this.GetString("ip")
	port,_ := this.GetInt("port")

	if req.Method == "GET"{
		this.TplName = "add_user.tpl"
	}else{
		qb,_:=orm.NewQueryBuilder("mysql")

		qb.InsertInto("sys_pro","game_name","server_type","db","ip","port").
        Values("?","?","?","?","?")

		sql := qb.String()
		fmt.Println(sql)
		// 执行 SQL 语句
		o := orm.NewOrm()
		_,err := o.Raw(sql,game_name,server_type,database,ip,port).Exec()
	
		if err == nil{
			this.Suc("添加成功")
		}else{
			fmt.Println(err)
			this.Faild(-1,"添加失败")
		}
	}
}
 
